package shuaige.jdk.多线程.锁.可重入锁_synchronized;

public class synchronized_非线程同步 {

    public static void main(String[] args) throws InterruptedException {
        var add = new AddThread();
        var dec = new DecThread();
        add.start();
        dec.start();
        add.join();
        dec.join();
        System.out.println(Counter_非线程同步.count);
    }


    static class Counter_非线程同步 {
        public static int count = 0;
    }

    static class AddThread extends Thread {
        @Override
        public void run() {
            for (int i = 0; i < 10000; i++) {
                Counter_非线程同步.count += 1;
            }
        }
    }

    static class DecThread extends Thread {
        @Override
        public void run() {
            for (int i = 0; i < 10000; i++) {
                Counter_非线程同步.count -= 1;
            }
        }
    }

}
